package net.mikoo.seals.task;

import java.util.concurrent.TimeUnit;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Lazy;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import com.gson.WeChat;

import net.mikoo.seals.common.WebContext;

@Component 
@Lazy(false)
public class MyTask{
	
	private Logger logger = LoggerFactory.getLogger(MyTask.class);
	
	@Value("${wechat.appid}")
	private String appid;
	
	@Value("${wechat.appsecret}")
	private String secret;
	
	@Autowired
	private RedisTemplate<String, String> redisTemplate;
	
	
	@Scheduled(cron = "0 0 0/1 * * ?" ) 
	//@Scheduled(cron = "0/1 * * * * ?" ) 
	public void pullDtas() {
		logger.info("===========获取wechat Asset Token执行开始===========>");
		try {
			String accessToken = WeChat.getAccessToken();
			redisTemplate.opsForValue().set(WebContext.WECHAT_ACCESS_TOKEN, accessToken, 2, TimeUnit.HOURS);;
		} catch (Exception e) {
			logger.info("===========获取wechat Asset Token执行失败===========>",e);
		}
		logger.info("===========获取wechat Asset Token执行结束===========>result={}","1");
	}
	
	
	
}